/**
 * @author mapeng
 * @version 2017-05-09
 */

(function(doc, win) {
    
        var pageVariables = {
            "loadFromCache" : false , 
            "shopId" : "" , 
            "type" : "" , 
            "handleBack4WeixinOpenStep1" : "",
            "handleForward" : "",
            "handleBack" : ""
        };
    
        $(doc).on("pageInit", "#weixinChangeBaseInfo", function(e, pageId, $page, isBack , isForward) {
            if(isForward)	return;
    
            if(isBack){
                handlePageBack();
                return;
            }
    
            init4Page();
        });
        bindEvents4Page();
    
        //页面返回
        function handlePageBack(){
    
            var params = CommonUtil.takeOutParamObject() || {};
            pageVariables.handleForward = params.handleForward || "load";
    
            params.handleForward = "";
            CommonUtil.injectParamObject(params);
        }
    
        // //前进
        // function doForward(){
        //     if(pageVariables.loadFromCache == true){
        //         $.router.forward();
        //     }else{
        //         $.router.load("weixin_open_step2.html",true); // ignore cache
        //     }
        // }
    
        //页面进入
        function handlePageLoad(){
            var params = CommonUtil.takeOutParamObject() || {};
            pageVariables.handleBack = params.handleBack || "back";
            params.handleBack = "";
            CommonUtil.injectParamObject(params);
        }
    
        //返回
        function doBack(){
    
            if(pageVariables.handleBack == "back"){
                $.router.back();
            }else if(pageVariables.handleBack == "load"){
                var cache = CommonUtil.takeOutParamObject() || {};
                cache.shopId = pageVariables.shopId;
                cache.handleBack = "load";
                CommonUtil.injectParamObject(cache);
                $.router.load("store_detail.html",true);
            }
        }
    
        //处理返回进入
        function handleFromBack(){
    
            var params = CommonUtil.takeOutParamObject() || {};
            if(params.backFrom == "weixinOpenStep2Page"){
                pageVariables.loadFromCache = true;
            }else{
                pageVariables.loadFromCache = false;
            }
    
            params.backFrom = "";
            CommonUtil.injectParamObject(params);
        }
    
        //页面初始化
        function init4Page(){
    
            //页面参数
            var params = CommonUtil.takeOutParamObject() || {};
            pageVariables.shopId = params.shopId;
            pageVariables.type = params.type;
    
            handlePageLoad();
    
            //行业分类
            init4IndustryType();
    
            //门店所在地区
            init4ShopDistrict();
            
            initBaseAccountInfo();
        }

        function initBaseAccountInfo(){

            //查询门店
		CommonUtil.sendJsonpRequest({
            // apiTest.testStoreDetail({
                "url" : App.serverUrl+"/app/shop/getShopDetail.do",
                "params" : {"shopId" : pageVariables.shopId},
                "success" : function(result){
                    if(result.success.toString() == "true"){//success
                        pageVariables.shop = result.resultObject;
    
                        //查询微信账户
                        CommonUtil.sendJsonpRequest({
                        // apiTest.testGetAccount({
                            "url" : App.serverUrl+"/app/wxAccount/getshopBaseInfoByShopId.do",
                            "params" : {"shopId" : pageVariables.shopId , "merchantId" : pageVariables.shop.merchantId},
                            "success" : function(result){
                                if(result.success.toString() == "true"){
                                    debugger
                                    pageVariables.weixinAccount = result.resultObject;
                                    // CommonUtil.render($("#weixinChangeBaseInfo .page-body"), "weixinChangeTPL",{"data":result.resultObject,"utils":{"extractFilePath" : extractFilePath},"constants" : $.extend(Constants,{"previewUrlPrefix" : App.previewUrlPrefix})},false);
                                    $("#shopName").val(pageVariables.weixinAccount.merchantName);
                                    $("#shortShopName").val(pageVariables.weixinAccount.merchantShortName);
                                    // var tempHiIn = $("#weixinChangeBaseInfo div[name='industryType']>input[type='hidden']");
                                    $("#weixinChangeBaseInfo div[name='industryType']>ul").mobiscroll("setVal",pageVariables.weixinAccount.industrName,true);
                                    $("#weixinChangeBaseInfo div[name='industryType']>input[type='hidden']").val(pageVariables.weixinAccount.industrId);
                                    $("#weixinChangeBaseInfo div[name='shopDistrict']>ul").mobiscroll("setArrayVal",[pageVariables.weixinAccount.provinceName,pageVariables.weixinAccount.cityName,pageVariables.weixinAccount.countyName],true);
                                    $("#weixinChangeBaseInfo div[name='shopDistrict']>input[type='hidden']").val(pageVariables.weixinAccount.province+","+pageVariables.weixinAccount.city + "," + pageVariables.weixinAccount.county);
                                    $("#address").val(pageVariables.weixinAccount.address);
                                    $("#bossName").val(pageVariables.weixinAccount.legalPerson);
                                    $("#businessRegistrationNum").val(pageVariables.weixinAccount.businessRegistrationNum);
                                    //控制图片显示
                                    if(pageVariables.weixinAccount.yzBusinessPhoto){
                                        $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("yzImgUrl",extractFilePath(pageVariables.weixinAccount.yzBusinessPhoto));
                                    }
                                    if(pageVariables.weixinAccount.businessPhoto){
                                        $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("weixinImgUrl",pageVariables.weixinAccount.businessPhoto);
                                    }
                                    if(pageVariables.weixinAccount.yzOrgPhoto){
                                        $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("yzImgUrl",extractFilePath(pageVariables.weixinAccount.yzOrgPhoto));
                                    }
                                    if(pageVariables.weixinAccount.orgPhoto){
                                        $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("weixinImgUrl",pageVariables.weixinAccount.orgPhoto);
                                    }
                                    if(pageVariables.weixinAccount.yzDoorheadPhoto){
                                        $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("yzImgUrl",extractFilePath(pageVariables.weixinAccount.yzDoorheadPhoto));
                                    }
                                    if(pageVariables.weixinAccount.doorheadPhoto){
                                        $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("weixinImgUrl",pageVariables.weixinAccount.doorheadPhoto);
                                    }
                                    if(pageVariables.weixinAccount.yzBusinessPhoto){
                                        displayPicture($("#weixinChangeBaseInfo li[name='businessPhoto']"),"show");
                                        $("#weixinChangeBaseInfo li[name='businessPhoto']").find("img").attr("src",App.previewUrlPrefix + extractFilePath(pageVariables.weixinAccount.yzBusinessPhoto));
                                    }
                                    if(pageVariables.weixinAccount.yzOrgPhoto){
                                        displayPicture($("#weixinChangeBaseInfo li[name='orgPhoto']"),"show");
                                        $("#weixinChangeBaseInfo li[name='orgPhoto']").find("img").attr("src",App.previewUrlPrefix + extractFilePath(pageVariables.weixinAccount.yzOrgPhoto));
                                    }
                                    if(pageVariables.weixinAccount.yzDoorheadPhoto){
                                        displayPicture($("#weixinChangeBaseInfo li[name='doorheadPhoto']"),"show");
                                        $("#weixinChangeBaseInfo li[name='doorheadPhoto']").find("img").attr("src",App.previewUrlPrefix + extractFilePath(pageVariables.weixinAccount.yzDoorheadPhoto));
                                    }
                                    listen4NextStep();
                                }else{//business error
                                    DialogUtil.dialogWarn(result.msg);
                                }
                            },
                            "error" : function(){//not 200
                                DialogUtil.dialogWarn("请求失败，请稍候重试");
                            }
                        });
    
                    }else{//business error
                        DialogUtil.dialogWarn(result.msg);
                    }
                },
                "error" : function(){//not 200
                    DialogUtil.dialogWarn("请求失败，请稍候重试");
                }
            });
        }
        //提取图片地址path（老数据带域名）
        function extractFilePath(path){
            if(/^http/.test(path)){
                path = path.replace(App.previewUrlPrefix,"");
            }
            return path;
        }
        // //初始化行业分类
        // function init4IndustryType(){
        //     debugger
        //     var industryTypeUl = "<ul style='display:none;'>";
        //     $.each(Constants.weixin.INDUSTRY_TYPE,function(key,value){
        //         industryTypeUl += "<li data-code='"+value+"' data-val='"+Constants.weixin.getIndustryTypeText(value)+"'>"+Constants.weixin.getIndustryTypeText(value)+"</li>";
        //     });
        //     industryTypeUl += "</ul>";
        //     $("#weixinChangeBaseInfo div[name='industryType']").prepend(industryTypeUl);
    
        //     $("#weixinChangeBaseInfo div[name='industryType']").children("ul").mobiscroll().treelist({
        //         "theme": "ios",
        //         "display": "bottom",
        //         "lang": "zh",
        //         "placeholder": "请选择行业",
        //         "onSelect" : function(valueText,inst){
        //             var $ul = $(this);
        //             var $li = $ul.children("li[data-val='"+valueText+"']");
        //             var code = $li.attr("data-code");
        //             $ul.parent().find("input[type='hidden']").val(code);
    
        //             listen4NextStep();
        //         }
        //     });
        // }
        //初始化行业分类
        function init4IndustryType(){
            debugger
            var industryTypeUl = "<ul style='display:none;'>";
            $.each(Constants.weixin.INDUSTRY_TYPE,function(key,value){
                industryTypeUl += "<li data-code='"+value+"' data-val='"+Constants.weixin.getIndustryTypeText(value)+"'>"+Constants.weixin.getIndustryTypeText(value)+"</li>";
            });
            industryTypeUl += "</ul>";
            var aaa = $("#weixinChangeBaseInfo");
            $("#industryType1").prepend(industryTypeUl);
    
            $("#industryType1").children("ul").mobiscroll().treelist({
                "theme": "ios",
                "display": "bottom",
                "lang": "zh",
                "placeholder": "请选择行业",
                "onSelect" : function(valueText,inst){
                    var $ul = $(this);
                    var $li = $ul.children("li[data-val='"+valueText+"']");
                    var code = $li.attr("data-code");
                    $ul.parent().find("input[type='hidden']").val(code);
    
                    listen4NextStep();
                }
            });
        }
    
        //初始化门店地区
        function init4ShopDistrict(){
    
            common.loading();
            CityUtil.getProviceCityAreaHtml(function(ul){
                common.closeLoading();
                $("#weixinChangeBaseInfo div[name='shopDistrict']").prepend(ul);
                $("#weixinChangeBaseInfo div[name='shopDistrict']").children("ul").mobiscroll().treelist({
                    "theme": "ios",
                    "display": "bottom",
                    "lang": "zh",
                    "placeholder": "请选择省、市、区(县)",
                    "formatValue" : function(data){
                        return data.join("-");
                    },
                    "onSelect" : function(valueText,inst){
                        var codeArray = [];
                        var $ul = $this = $(this);
                        $.each(valueText.split("-"),function(index,value){
                            var $li = $ul.children("li[data-val='"+value+"']");
                            codeArray.push($li.attr("data-code"));
                            $ul = $li.children("ul").eq(0);
                        });
                        $this.parent().find("input[type='hidden']").val(codeArray.join(","));
    
                        listen4NextStep();
                    }
                });
            });
        }
    
        //校验返回
        function confirm4Back(){
    
            var shopName = $("#weixinChangeBaseInfo input[name='shopName']").val().trim();
            var shortShopName = $("#weixinChangeBaseInfo input[name='shortShopName']").val().trim();
            var industryType = $("#weixinChangeBaseInfo div[name='industryType'] input[type='hidden']").val();
            var shopDistrict = $("#weixinChangeBaseInfo div[name='shopDistrict'] input[type='hidden']").val();
            var address = $("#weixinChangeBaseInfo input[name='address']").val().trim();
            var bossName = $("#weixinChangeBaseInfo input[name='bossName']").val().trim();
            var businessRegistrationNum = $("#weixinChangeBaseInfo input[name='businessRegistrationNum']").val();
            var businessPhoto = $("#weixinOpenStep2Page li[name='businessPhoto']").attr("weixinImgUrl"); 
            var orgPhoto = $("#weixinOpenStep2Page li[name='orgPhoto']").attr("weixinImgUrl"); 
            var doorheadPhoto = $("#weixinOpenStep2Page li[name='doorheadPhoto']").attr("weixinImgUrl"); 
            var yzBusinessPhoto = $("#weixinOpenStep2Page li[name='businessPhoto']").attr("yzImgUrl"); 
            var yzOrgPhoto = $("#weixinOpenStep2Page li[name='orgPhoto']").attr("yzImgUrl"); 
            var yzDoorheadPhoto = $("#weixinOpenStep2Page li[name='doorheadPhoto']").attr("yzImgUrl"); 
    
            //没有填写任何表单
            if(!shopName && !shortShopName && !industryType && !shopDistrict && !address && !bossName && !businessRegistrationNum && !businessPhoto 
                && !orgPhoto && !doorheadPhoto && !yzBusinessPhoto && !yzOrgPhoto && !yzDoorheadPhoto){
                doBack();
                return;
            }
    
            //已填写：需要确认是否放弃
            DialogUtil.dialogConfirm({
                "title" : "",
                "content" : "离开页面将不会保存本次修改，确定要离开吗？",
                "btnLeft" : "取消",
                "btnRight" : "确定",
                "callbackLeft" : function(){},
                "callbackRight" : function(){
                    doBack();
                }
            });
        }
    
        //控制“下一步”是否可点击
        function listen4NextStep(){
            debugger
            var shopName = $("#weixinChangeBaseInfo input[name='shopName']").val().trim();
            var shortShopName = $("#weixinChangeBaseInfo input[name='shortShopName']").val().trim();
            var industryType = $("#weixinChangeBaseInfo div[name='industryType'] input[type='hidden']").val();
            var shopDistrict = $("#weixinChangeBaseInfo div[name='shopDistrict'] input[type='hidden']").val();
            var address = $("#weixinChangeBaseInfo input[name='address']").val();
            var bossName = $("#weixinChangeBaseInfo input[name='bossName']").val();
            var businessRegistrationNum = $("#weixinChangeBaseInfo input[name='businessRegistrationNum']").val();
            var businessPhoto = $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("weixinImgUrl"); 
            var orgPhoto = $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("weixinImgUrl"); 
            var doorheadPhoto = $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("weixinImgUrl"); 
            var yzBusinessPhoto = $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("yzImgUrl"); 
            var yzOrgPhoto = $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("yzImgUrl"); 
            var yzDoorheadPhoto = $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("yzImgUrl"); 
            // $("#weixinChangeBaseInfo .header li.right").removeClass("disabled");
            // return;
            if (shopName && shortShopName && industryType && shopDistrict && address && bossName && businessRegistrationNum && businessPhoto 
                && orgPhoto && doorheadPhoto && yzBusinessPhoto && yzOrgPhoto && yzDoorheadPhoto) {
                $("#weixinChangeBaseInfo .header li.right").removeClass("disabled");
                return;
            }
    
            $("#weixinChangeBaseInfo .header li.right").addClass("disabled");
        }
    
        //下一步
        function next(){
    
            //表单数据
            var shopName = $("#weixinChangeBaseInfo input[name='shopName']").val().trim();
            var shortShopName = $("#weixinChangeBaseInfo input[name='shortShopName']").val().trim();
            var industryType = $("#weixinChangeBaseInfo div[name='industryType'] input[type='hidden']").val();
            var industryTypeText = $("#weixinChangeBaseInfo div[name='industryType']>ul").mobiscroll("getVal");
            var shopDistrict = $("#weixinChangeBaseInfo div[name='shopDistrict'] input[type='hidden']").val();
            var shopDistrictText = $("#weixinChangeBaseInfo div[name='shopDistrict']>ul").mobiscroll("getArrayVal");
            var address = $("#weixinChangeBaseInfo input[name='address']").val().trim();
            var bossName = $("#weixinChangeBaseInfo input[name='bossName']").val().trim();
            var businessRegistrationNum = $("#weixinChangeBaseInfo input[name='businessRegistrationNum']").val();
            var businessPhoto = $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("weixinImgUrl"); 
            var orgPhoto = $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("weixinImgUrl"); 
            var doorheadPhoto = $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("weixinImgUrl"); 
            var yzBusinessPhoto = $("#weixinChangeBaseInfo li[name='businessPhoto']").attr("yzImgUrl"); 
            var yzOrgPhoto = $("#weixinChangeBaseInfo li[name='orgPhoto']").attr("yzImgUrl"); 
            var yzDoorheadPhoto = $("#weixinChangeBaseInfo li[name='doorheadPhoto']").attr("yzImgUrl"); 
    
            //校验：门店名称
            if(shopName.length == 0){
                DialogUtil.dialogWarn("请填写门店名称");
                return;
            }
            if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(shopName)){
                DialogUtil.dialogWarn("门店名称仅允许输入中文、英文、数字");
                return;
            }
            if(CommonUtil.countBytes(shopName,2) > 64){
                DialogUtil.dialogWarn("门店名称输入过长");
                return;
            }
    
            //校验：简称
            if(shortShopName.length == 0){
                DialogUtil.dialogWarn("请填写简称");
                return;
            }
            if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(shortShopName)){
                DialogUtil.dialogWarn("简称仅允许输入中文、英文、数字");
                return;
            }
            if(CommonUtil.countBytes(shortShopName,2) > 30){
                DialogUtil.dialogWarn("简称输入过长");
                return;
            }
    
            //校验：行业类别
            if(!industryType){
                DialogUtil.dialogWarn("请选择行业类别");
                return;
            }
    
            //校验：所在地区
            if(!shopDistrict){
                DialogUtil.dialogWarn("请选择所在地区");
                return;
            }
    
            //校验：详细地址
            if(address.length == 0){
                DialogUtil.dialogWarn("请填写详细地址");
                return;
            }
            if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(address)){
                DialogUtil.dialogWarn("详细地址仅允许输入中文、英文、数字");
                return;
            }
            if(CommonUtil.countBytes(address,2) > 128){
                DialogUtil.dialogWarn("详细地址输入过长");
                return;
            }
    
            //校验：企业法人
            if(bossName.length == 0){
                DialogUtil.dialogWarn("请填写企业法人");
                return;
            }
            if(!/^[\dA-Za-z\u4e00-\u9fa5]+$/.test(bossName)){
                DialogUtil.dialogWarn("企业法人仅允许输入中文、英文、数字");
                return;
            }
            if(CommonUtil.countBytes(bossName,2) > 128){
                DialogUtil.dialogWarn("企业法人输入过长");
                return;
            }
    
            //保存本页数据
            // var cache = CommonUtil.takeOutParamObject() || {};
            // cache.shopId = pageVariables.shopId;
            // cache.type = pageVariables.type;
            var stepOne = {
                "shopId" : pageVariables.shopId,
                "merchantId" : pageVariables.shop.merchantId,
                "merchantName" : shopName , 	//门店名称
                "merchantShortName" : shortShopName , 	//简称
                "industrId" : industryType , 	//行业类别
                "industrName" : industryTypeText,
                "province" : shopDistrict.split(",")[0],	//省
                "city" : shopDistrict.split(",")[1],	//市 
                "county" : shopDistrict.split(",")[2], //区
                "provinceName" : shopDistrictText[0],
                "cityName" : shopDistrictText[1],
                "countyName" : shopDistrictText[2],
                "address" : address , //详细地址
                "legalPeople" : bossName, //企业法人
                "businessRegistrationNum": businessRegistrationNum,//营业执照工商注册号
                "orgPhoto": orgPhoto,//组织机构照
                "businessPhoto": businessPhoto,//营业执照
                "doorheadPhoto": doorheadPhoto,//门头照
                "yzOrgPhoto": yzOrgPhoto,//云纵组织机构照
                "yzBusinessPhoto": yzBusinessPhoto,//云纵营业执照
                "yzDoorheadPhoto": yzDoorheadPhoto,//云纵门头照
            };
            // CommonUtil.injectParamObject(cache);
    
            common.loading("提交中");
            // CommonUtil.sendJsonpRequest({
            //     // apiTest.testStoreDetail({
            //         "url" : App.serverUrl+"/app/wxAccount/shopBaseInfoChange.do",
            //         "params" : JSON.stringify(stepOne),
            //         "success" : function(result){
            //             common.closeLoading();
                        
            //             var cache = CommonUtil.takeOutParamObject() || {};
            //             cache.shopId = pageVariables.shopId;
            //             CommonUtil.injectParamObject(cache);
            //             if(result.success.toString() == "true" && result.resultObject.success.toString() == "true"){//success
            //                 $.router.load("weixin_change_success.html");
            //             }else{
            //                 var errorMsg = "";
            //                 if(result.success.toString() == "false"){//app error
            //                     errorMsg = result.msg;
            //                 }else if(result.resultObject.success.toString() == "false"){//server error
            //                     errorMsg = result.resultObject.msg;
            //                 }
                            
            //                 var cache = CommonUtil.takeOutParamObject() || {};
            //                 cache.errorMsg = errorMsg;
            //                 CommonUtil.injectParamObject(cache);
            //                 $.router.load("weixin_change_error.html");
            //             }
            //         },
            //         "error" : function(){//not 200
            //             DialogUtil.dialogWarn("请求失败，请稍候重试");
            //         }
            //     });
            // }

            AppUtil.call(
                // weixinOpenStep1Test.testSubmit(
                AppUtil.APIS.SEND_HTTP_REQUEST,
                {
                    "type":"POST",
                    "url":App.serverUrl+"/app/wxAccount/shopBaseInfoChange.do",
                    "data" : JSON.stringify(stepOne)
                },
                function(result){
                    common.closeLoading();
                    
                    var cache = CommonUtil.takeOutParamObject() || {};
                    cache.shopId = pageVariables.shopId;
                    CommonUtil.injectParamObject(cache);
    
                    if(result.success.toString() == "true" && result.resultObject.success.toString() == "true"){//success
                        $.router.load("weixin_change_success.html");
                    }else{
                        var errorMsg = "";
                        if(result.success.toString() == "false"){//app error
                            errorMsg = result.msg;
                        }else if(result.resultObject.success.toString() == "false"){//server error
                            errorMsg = result.resultObject.msg;
                        }
                        
                        var cache = CommonUtil.takeOutParamObject() || {};
                        cache.errorMsg = errorMsg;
                        CommonUtil.injectParamObject(cache);
                        $.router.load("weixin_change_error.html");
                    }
                }
            );
        }
    
        //页面事件绑定
        function bindEvents4Page(){
    
            //返回
            $(document).on("click","#weixinChangeBaseInfo .header a.back",function(e){
                confirm4Back();
            });
    
            //监听输入，控制下一步是否可点击
            var listenFormStr = "#weixinChangeBaseInfo input[name='shopName']," + 
                                "#weixinChangeBaseInfo input[name='shortShopName']," + 
                                "#weixinChangeBaseInfo input[name='address']," + 
                                "#weixinChangeBaseInfo input[name='bossName']," +
                                "#businessRegistrationNum"; 
            $(document).on("input",listenFormStr,function(e){
                listen4NextStep();
            });
            $(document).on("clearInput","#weixinChangeBaseInfo .zhk-list_gb",function(e){
                listen4NextStep();
            });
            
            //营业执照
            $(document).on("click","#weixinChangeBaseInfo input[type='file']",function(e){//阻止file默认行为
                e.preventDefault();
            });	
            $(document).on("click","#weixinChangeBaseInfo li.picture",function(e){//上传
                if($(e.target).hasClass("zhk-list_gb"))	return;
    
                uploadPicture($(this));
            });	
            $(document).on("click","#weixinChangeBaseInfo .picture .zhk-list_gb",function(e){//删除
                var $li = $(this).parents("li.picture");
                displayPicture($li,"hide");
    
                $li.attr("yzImgUrl","");
                $li.attr("weixinImgUrl","");
    
                listen4NextStep();
            });
    
            //下一步
            $(document).on("click","#weixinChangeBaseInfo .header a[name='nextStep']",function(e){
    
                if($(this).parents("li.right").hasClass("disabled"))	return;
    
                next();
            });
        }
    
            //上传身份证照片
            function uploadPicture(target){
                
                $.actions([[{
                    "text" : "相册",
                    "onClick" : function(){
        
                        //选择
                        
                        AppUtil.call(AppUtil.APIS.SELECT_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
                            if(selectResult.success.toString() == "true"){
                                var filePath = selectResult.resultObject[0];
        
                                //上传
                                common.loading("上传中");
                                AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
                                    common.closeLoading();
                                    if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
                                        target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
                                        target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);
        
                                        //显示图片
                                        target.find("img").attr("src",filePath);
                                        displayPicture(target,"show");
        
                                        listen4NextStep();
                                    }else{
                                        var msg = "";
                                        if(uploadResult.success.toString() == "false"){
                                            msg = uploadResult.msg;
                                        }else if(uploadResult.resultObject.success.toString() == "false"){
                                            msg = uploadResult.resultObject.msg;
                                        }
                                        DialogUtil.dialogWarn(msg);
                                    }
                                });
                            }else{
                                DialogUtil.dialogWarn(selectResult.msg);
                            }
                        })
                    }
                },{
                    "text" : "拍照",
                    "onClick" : function(){
        
                        //拍照
                        AppUtil.call(AppUtil.APIS.TAKE_PICTURE,{"compress":{"sizeLimit":"500","unit":"K"},"format":"JPG","maxNum":"1"},function(selectResult){
                            if(selectResult.success.toString() == "true"){
                                var filePath = selectResult.resultObject;
        
                                //上传
                                common.loading("上传中");
                                AppUtil.call(AppUtil.APIS.UPLOAD_PICTURE,{"url":App.serverUrl+"/app/img/upload.do","file":filePath,"data":{"shopId":pageVariables.shopId,"uploadType":target.attr("uploadType")}},function(uploadResult){
                                    common.closeLoading();
                                    if(uploadResult.success.toString() == "true" && uploadResult.resultObject.success.toString() == "true"){
                                        target.attr("yzImgUrl",uploadResult.resultObject.resultObject.imageUrl);
                                        target.attr("weixinImgUrl",uploadResult.resultObject.resultObject.thirdPartyImageUrl);
        
                                        //显示图片
                                        target.find("img").attr("src",filePath);
                                        displayPicture(target,"show");
        
                                        listen4NextStep();
                                    }else{
                                        var msg = "";
                                        if(uploadResult.success.toString() == "false"){
                                            msg = uploadResult.msg;
                                        }else if(uploadResult.resultObject.success.toString() == "false"){
                                            msg = uploadResult.resultObject.msg;
                                        }
                                        DialogUtil.dialogWarn(msg);
                                    }
                                });
                            }else{
                                DialogUtil.dialogWarn(selectResult.msg);
                            }
                        })
                    }
                }],[{
                    "text" : "取消",
                    "color" : "danger",
                    "onClick" : function(){
                    }
                }]]);
                
            }
    
            function displayPicture(target,showOrHide){
                
                if(showOrHide == "show"){
                    target.find("div.upload-before").hide();
                    target.find("div.upload-after").show();
                }else if(showOrHide == "hide"){
                    target.find("div.upload-before").show();
                    target.find("div.upload-after").hide();
                }
            }
    
        /**
         * 测试接口
         * @type {Object}
         */
        var weixinOpenStep1Test = {
            "testSubmit" : function(apiName,params,callback){//提交
                callback({
                    "code" : "0",
                    "msg" : "",
                    "resultObject" : {
                        "code" : "0",
                        "msg" : "",
                        "success" : true,
                        "resultObject" : ""
                    },
                    "success" : true
                });
            },
            "testSendVerifyCode" : function(options){//发送验证码
                options.success({
                    "success" : true
                });
            },
        };
    
    })(document, window);